package com.hongxun.budget.ui.fragment.sg;

import android.widget.EditText;

import com.hongxun.budget.R;
import com.hongxun.budget.ui.fragment.BaseFragment;
import com.hongxun.budget.utils.SPUtils;
import com.hongxun.budget.utils.SgDBUtils;
import com.hongxun.budget.utils.SgStrKey;
import com.hongxun.greenentity.sg.CLinePitEntity;

import java.util.Date;

import butterknife.BindView;

/**
 * 隐蔽工程信息详情：拉线坑
 */
public class EditAnchorPitInfo extends BaseFragment {
    @BindView(R.id.et11)
    EditText et11;
    @BindView(R.id.et12)
    EditText et12;
    @BindView(R.id.et13)
    EditText et13;
    @BindView(R.id.et14)
    EditText et14;
    @BindView(R.id.et15)
    EditText et15;

    private CLinePitEntity linePitEntity;

    public EditAnchorPitInfo() {
    }

    @Override
    public int getLayoutId() {
        return R.layout.sg_fragment_editanchorpitinfo;
    }

    @Override
    public void initView() {
        if (getArguments().getBoolean("isNewAdd", false)) {
            linePitEntity = new CLinePitEntity();
            linePitEntity.setGuid(String.valueOf(SPUtils.get(context, SgStrKey.uuidxx, "")));
            linePitEntity.setPGuid(String.valueOf(SPUtils.get(context, SgStrKey.uuidxm, "")));
            linePitEntity.setMCGuid(String.valueOf(SPUtils.get(context, SgStrKey.uuidjl, "")));
            linePitEntity.setLPDatastate("新增");
            linePitEntity.setLPResult("合格");
            //默认值
            et15.setText(linePitEntity.getLPResult());
        } else {
            linePitEntity = SgDBUtils.getCLinePit(String.valueOf(SPUtils.get(context, SgStrKey.uuidxx, "")));
            et11.setText(linePitEntity.getLPDesigndepth());
            et12.setText(linePitEntity.getLPActualdepth());
            et13.setText(linePitEntity.getLPSoil());
            et14.setText(linePitEntity.getLPStone());
            et15.setText(linePitEntity.getLPResult());
        }
    }

    //保存
    public void saveData(String name) {
        String trim11 = et11.getText().toString().trim();//设计坑深
        String trim12 = et12.getText().toString().trim();//实测坑深
        String trim13 = et13.getText().toString().trim();//土层深度
        String trim14 = et14.getText().toString().trim();//砂石深度
        String trim15 = et15.getText().toString().trim();
        linePitEntity.setMCName(name);
        linePitEntity.setLPDesigndepth(trim11);
        linePitEntity.setLPActualdepth(trim12);
        linePitEntity.setLPSoil(trim13);
        linePitEntity.setLPStone(trim14);
        linePitEntity.setLPResult(trim15);
        linePitEntity.setLPAddtime(new Date(System.currentTimeMillis()));
        SgDBUtils.upDataCLinePitEntity(linePitEntity);
    }
}
